//index.js
//获取应用实例
const app = getApp()
import {
    request
} from '../../request/index.js'

Page({
    data: {
        swiperList: [],
        catesList: [],
        floorList: []
    },

    onLoad: function() {

        this.getSwiperList()
        this.getCatesList()
        this.getFloorList()

    },

    // 获取轮播图数据
    getSwiperList() {
        var that = this
        request({
            url: '/home/swiperdata'
        }).then((data) => {

            const swiperList = data.data.message

            swiperList.forEach((v, i, arr) => {
                arr[i].navigator_url = arr[i].navigator_url.replace('/main\?', '/goods_detail\?')
            });

            that.setData({
                swiperList
            })
        })
    },

    // 获取导航数据
    async getCatesList() {
        const {
            data
        } = await request({
            url: '/home/catitems'
        })

        this.setData({
            catesList: data.message
        })

        // request({
        //   url: '/home/catitems'
        // }).then((data) => {
        //   that.setData({
        //     catesList: data.data.message
        //   })
        // })
    },

    // 获取楼层数据
    async getFloorList() {

        // request({
        //   url: '/home/floordata'
        // }).then((data) => {
        //   that.setData({
        //     floorList: data.data.message
        //   })
        // })
        const {
            data
        } = await request({
            url: '/home/floordata'
        })

        // 处理楼层数据，修正navigator url
        const floorList = data.message

        floorList.forEach((v, i, arr) => {

            v.product_list.forEach((v1, i1, arr1) => {
                arr1[i1].navigator_url = v1.navigator_url.replace('/goods_list\?', '/goods_list/goods_list\?')
            });

            arr[i].product_list = v.product_list

        });

        this.setData({
            floorList
        })
    }
})